package designpattern.single;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

//单例模式的扩展
public class Emperors {

    private static Integer MAX_EMPEROR_NUMBER = 2;

    private static List<Emperors> list = new ArrayList<>();

    private static  int countNumber = 0;

    private static List<String> nameList = new ArrayList<>();

    private Emperors(String name){

       nameList.add(name);
    }
    private Emperors(){

    }


    static{

        for(int i=0;i<MAX_EMPEROR_NUMBER;i++){

             list.add(new Emperors("皇"+(i+1)+"帝"));

        }
    }
    public static Emperors getEmperors(){

        Random random = new Random();
        countNumber = random.nextInt(MAX_EMPEROR_NUMBER);
        return list.get(countNumber);

    }
    public  static  void say(){

        System.out.println(nameList.get(countNumber));
    }
}
